import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:qunaimedical/components/custom_avatar.dart';
import 'package:qunaimedical/models/patient.dart';
import 'package:qunaimedical/pages/patient_manage/check_item_list.dart';
import 'package:qunaimedical/pages/patient_manage/patient_record_list.dart';
import 'package:qunaimedical/utils/common_util.dart';
import 'package:qunaimedical/values/constants.dart';

/// 患者数据条目
class ItemPatient extends StatelessWidget {
  final Patient item;
  final VoidCallback onDelete;
  final GestureTapCallback onTap;

  const ItemPatient({Key key, this.item, this.onDelete, this.onTap})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Slidable(
      actionPane: SlidableScrollActionPane(),
      actionExtentRatio: 0.2,
      secondaryActions: <Widget>[
        IconSlideAction(
          caption: '删除',
          color: Colors.red,
          icon: Icons.delete_forever,
          onTap: onDelete,
        ),
      ],
      child: InkWell(
        onTap: onTap,
        child: Container(
          color: Colors.white,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Row(
                children: [
                  CustomAvatar(
                    avatarUrl: item.avatar,
                    margin: EdgeInsets.all(16),
                  ),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          Text(
                            item.fullname ?? '',
                            style: TextStyle(
                                fontSize: 18, fontWeight: FontWeight.bold),
                          ),
                          SizedBox(width: 20),
                          Text(CommonUtils.isNumeric(item.sex)
                              ? Constants.genderData[int.parse(item.sex)]
                              : ''),
                          SizedBox(width: 20),
                          Text('${item.age}岁'),
                        ],
                      ),
                      SizedBox(height: 5),
                      Text('患者电话：${item.cellphone}'),
                    ],
                  )
                ],
              ),
              Divider(),
              Container(
                height: 50,
                child: Row(
                  children: [
                    Expanded(
                      child: InkWell(
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            Image.asset('assets/images/ic_patient_case.png',
                                width: 18),
                            Container(
                              child: Text('病例'),
                              margin: EdgeInsets.only(left: 5),
                            ),
                          ],
                        ),
                        onTap: () {
                          Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (c) =>
                                      PatientRecordListPage(patient: item)));
                        },
                      ),
                    ),
                    Expanded(
                      child: InkWell(
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            Image.asset('assets/images/ic_patient_check.png',
                                width: 18),
                            Container(
                              child: Text('检查项'),
                              margin: EdgeInsets.only(left: 5),
                            ),
                          ],
                        ),
                        onTap: () {
                          Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (c) => CheckItemListPage(item)));
                        },
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
